class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            list: [],
            no: '',
            id: 0,
            counts: [],
            start: 1,
            pagesize: 15,
            keyword: "",
            type: 0,
            state: 'ON',
            typehtml: [],
            statehtml: [],
            merchantName:'',
            xdata:{

            }

        };
    }

    formatlist(list) {
        var listitem = [], wulist = [];
       
        if (list.length > 0) {
            list.forEach((x, i) => {
                listitem.push(
                    <tr key={i}>
                        <td className="tconter" style={{ width: '200px'}} >{x.payDepAcc}</td>
                        <td style={{ width: '200px' }}>{x.recDepAcc}</td>
                        <td className="tconter">{parseFloat(Number(x.payamt)/100.0) }元</td>
                        <td className="tconter">{getdetailstausstr(x.result)}</td>
                    </tr>
                )
            });
        } else {
            wulist.push(
                <p className="wulist">暂无数据 !</p>
            )
        }
        this.setState({ listitem, list, originallist: list, wulist })
    }


    componentDidMount() {
        console.log(localStorage.getItem('dlist'),'dlist');
       let userdata = JSON.parse($.cookie('userdata')),{merchantName}= userdata,
       data = JSON.parse(localStorage.getItem('dlist')),{x,list}=data;
       console.log(data,'datadatadata');
       this.setState({merchantName,xdata:x},()=>{
       
       })

        let pagecount = Math.ceil(x.totalCount / this.state.pagesize);
        this.setpager(pagecount,1);
        this.setState({ start:1, total: x.totalCount})
       this.formatlist(list);
       // console.log(JSON.parse(userdata),'ppp');
       
        
        // this.setState({ showloading: 'ON' })
        // let that = this, statehtml = [], typehtml = []
        // statehtml.push(
        //     <option value="ALL">全部</option>
        // )
        // statehtml.push(
        //     <option value="ON">上架</option>
        // )
        // statehtml.push(
        //     <option value="OFF">下架</option>
        // )
        // that.setState({ statehtml })
        // getTypelist(res => {
        //     if (res.issuccess == 1) {
        //         if (res.list.length > 0) {
        //             typehtml.push(
        //                 <option value="0">请选择</option>
        //             )
        //             res.list.forEach((x, i) => {
        //                 typehtml.push(
        //                     <option key={i} value={x.id}>{x.name} </option>
        //                 )

        //             })
        //             this.setState({ typehtml })
        //         }
        //     }
        // })
        $('.modal1').hide()
        // testdingcan(res=>{
        // })
       //  this.setState({ showloading: '' })
      //  this.freshlist()

    }
    freshlist() {
        let{xdata,pagesize,start} = this.state;

        gzgetDetail(xdata.id,pagesize,start,res=>{
            this.formatlist(res.data.datalist);
                })


        
        //  let { pagesize, start, no,x } = this.state
        //  list_getlist(pagesize,start,no,res=>{
        //      console.log(res,'resres');
        //     this.setState({ showloading: '' })
        //      if(res.data.total>0){
        //          if (start == 1) {
        //                         let pagecount = Math.ceil(x.totalCount / pagesize);
        //                         this.setpager(pagecount, start);
        //                         this.setState({ start, total: x.totalCount })
        //                     }
        //          this.formatlist(res.data.list);
              
        //      }
        //  })
    }
    setpager(pagecount, start) {
        let counts = [];
        for (let i = 0; i < pagecount; i++) {
            counts.push(start + i)
        }
        this.setState({ counts, pagestart: 0 })
    }
    clickpage(e) {
        console.log(e,'clickpage');
        let { start } = this.state
        if(start==e){
            start++;
        }else{
            start = e+1
        }

        this.setState({ pagestart: e, start }, () => {
            this.freshlist()
        })
    }
    setpage(e) {
        let { pagesize, start } = this.state
        pagesize = parseInt(e)
        start = 1
        this.setState({ pagesize, start }, () => {
            this.freshlist()
        })
    }
    inputchange(prop, e) {
        this.setState({ [prop]: e.target.value })
    }
    inputchange1(prop, id, e) {
        let that = this;
        if (prop == "state") {
            that.setState({ showloading: 'ON' })
            Shopsetstate(id, res => {
                if (res.issuccess == 1) {
                    alert("设置成功")
                    that.freshlist()
                } else {
                    that.setState({ showloading: '' })
                    alert(res.msg)
                }
            })
        } else if (prop == "isrecommend") {
            that.setState({ showloading: 'ON' })
            Shopsetrecommend(id, res => {
                if (res.issuccess == 1) {
                    alert("设置成功")
                    that.freshlist()
                } else {
                    that.setState({ showloading: '' })
                    alert(res.msg)
                }
            })
        }

    }
    back() {
      window.location.href='./list.html'
    }
    add() {
        window.location.href = "./additem.html";
    }
    reset() {
        this.setState({ state: 'ON', no: '' }, () => {
            this.freshlist()
        })
    }
    render() {
        let { listitem, xdata,sfzh, jine, result,merchantName } = this.state;
            
        return (
            <div className="breadLinebox">
                {/* <div className="modal1" >
                <div className="mask"></div>
                <div className="wrap">
                    <div className="close-div">
                        <img src="./src/close1.png" alt="" /> 
                    </div>
                    <div className="content">
                        <p className="p1">付方账号</p>
                        <p>{ffzh}</p>
                    </div>
                    <div className="content">
                        <p className="p1">收方账号</p>
                        <p>{sfzh}</p>
                    </div>
                    <div className="content">
                        <p className="p1">金额</p>
                        <p>{jine}</p>
                    </div>
                    <div className="content">
                        <p className="p1">状态</p>
                        <p>{result}</p>
                    </div>
                </div>

                </div> */}

                <Loading hidden={this.state.showloading != 'ON'} />
                <p className="merchantName">{merchantName}</p>
                <div className='panel-default content_wrap'>
                    <div className="breadLine disflexbetween">
                        <div className="img">
                            {/* <img src='./src/01.gif' /> */}
                       批次id:{xdata.batchNo} 总金额：{parseFloat(Number(xdata.totalAmt)/100.0)} 总笔数:{xdata.totalCount}  创建时间：{formatDate(new Date(xdata.createTime))}
                        </div>
                        <p className="button l" onClick={this.back.bind(this)} >返回</p>
                    </div>
                    <div className="disflexbetween">
                        {/* <div className="search ">
                            <div className="left">
                            <antd.Input placeholder="请输入批次号" allowClear value={no} onChange={this.inputchange.bind(this, 'no')} className="input" />
                            <p className="button l" onClick={this.search.bind(this)} >搜索</p>
                            <p className="button" onClick={this.reset.bind(this)} >重置</p>
                            </div>
                            <div className="tabletit">
                            <p className="add" onClick={this.add.bind(this)}><img src="./src/addicon.png"></img>新建</p>
                        </div>
                        </div> */}

                      
                    </div>
                    <div className="contentBox">

                        <table className="tab">
                            <thead>
                                <tr>
                                    <th className="tconter">付方账号</th>
                                    <th className="tconter">收方账号</th>
                                    <th className="tconter">金额</th>
                                    <th className="tconter">状态</th>
                                    {/* <th>是否新人专享</th>
                                    <th>是否会员专享</th> */}
                                </tr>
                            </thead>
                            <tbody>
                                {listitem}
                            </tbody>
                        </table>
                        {this.state.wulist}
                        <div className="pagerbox">
                            <p>共{this.state.total}条</p>
                            <Pager counts={this.state.counts} click={this.clickpage.bind(this)} change={this.setpage.bind(this)} index={this.state.pagestart} />
                        </div>
                    </div>
                    {/* <div class="jsfw">江西川星科技有限公司提供技术支持</div> */}
                </div>
            </div>


        )


    }
}

ReactDOM.render(
    <div>
        <TopLine />
        <div id='body'>
            <LeftMenu code='list' height='list' />
            <Main />
        </div>
    </div>
    // <Barrage/>
    , $('.container')[0]
)